package com.atguigu.daijia.driver.controller;

import com.atguigu.daijia.common.result.Result;
import com.atguigu.daijia.driver.service.CosService;
import com.atguigu.daijia.model.vo.driver.CosUploadVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@Tag(name = "腾讯云cos上传接口管理")
@RestController
@RequestMapping(value="/cos")
@SuppressWarnings({"unchecked", "rawtypes"})
public class CosController {

	@Autowired
	private CosService cosService;

	@Operation(summary = "上传")
	@PostMapping("/upload")
	/**
	 * 上传文件到云存储服务
	 *
	 * @param file 待上传的文件，通过表单形式提交
	 * @param path 文件在云存储中的路径
	 * @return 返回上传结果，包含上传文件的元数据
	 */
	public Result<CosUploadVo> upload(@RequestPart("file") MultipartFile file,
	                                  @RequestParam("path") String path) {
	    CosUploadVo cosUploadVo = cosService.upload(file, path);
	    return Result.ok(cosUploadVo);
	}

}

